/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    bool isSymmetric(TreeNode* root) {
        vector<int> ans1,ans2;
        ans1=layertorder(root,true);
        ans2=layertorder(root,false);
        return ans1==ans2;
    }
    vector<int> layertorder(TreeNode* root,bool flag){
        vector<int> res;
        queue<TreeNode*> que;
        que.push(root);
        TreeNode* tmp;
        while(!que.empty()){
            tmp=que.front();
            que.pop();
            if(tmp==nullptr){res.push_back(-999);continue;}
            else{res.push_back(tmp->val);}
            if(flag){
                que.push(tmp->left);
                que.push(tmp->right);
            }else{
                que.push(tmp->right);
                que.push(tmp->left);
            }
        }
        return res;
    }
};